<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../vue.js"></script>
</head>

<body>
  <div id="app">
  </div>
  <script>
    Vue.config.productionTip = false;
    /*
        使用Vue.extend方法 返回一个VueComponent构造函数
        当组件使用的时候，会把当前的VueComponent实例化，得到一个组件实例

        注意：
          1. 每次创建一个组件 都会得到一个不同的VueComponent构造函数
    */



    //1.创建组件
    const Count1 = Vue.extend({
      name: "Count1",
      data() {
        return {
          count: 0
        }
      },
      methods: {
        add() {
          this.count++
        }
      },
      template: `
        <div>
          <h1>{{count}}</h1>
          <button @click = "add" >累加</button>
        </div>
      `
    })

    const Count2 = {
      name: "Count2",
      data() {
        return {
          count: 0
        }
      },
      methods: {
        add() {
          this.count--
        }
      },
      template: `
        <div>
          <h1>{{count}}</h1>
          <button @click = "add" >累加</button>
        </div>
      `
    }



    console.log(Count1, "Count");
    console.log(Count2, "Count2");

    const vm = new Vue({
      el: "#app",
      data() {
        return {}
      },
      //2.注册组件
      components: {
        Count1,
        Count2,
      },
      template: `
        <div>
          <Count1/>
          <hr/>
          <Count2/>
        </div>
      `
    })
  </script>
</body>

</html>